import { UsePlugin } from '../utils/usePlugin';
import { AllPlugin } from '../plugins/Plugin';

export class PluginManager {
  protected globalPlugins: UsePlugin = new UsePlugin();
  protected localPlugins: UsePlugin = new UsePlugin();

  public appendGlobalPlugins(plugins?: UsePlugin<any, any> | AllPlugin<any, any>): void {
    if (plugins !== undefined) {
      this.globalPlugins.use(plugins);
    }
  }

  public appendLocalPlugins(plugins?: UsePlugin<any, any> | AllPlugin<any, any>): void {
    if (plugins !== undefined) {
      this.localPlugins.use(plugins);
    }
  }

  public getGlobalPlugins(): UsePlugin {
    return this.globalPlugins;
  }

  public getLocalPlugins(): UsePlugin {
    return this.localPlugins;
  }

  public clone(): PluginManager {
    const manager = new PluginManager();
    manager.appendGlobalPlugins(this.getGlobalPlugins());
    manager.appendLocalPlugins(this.getLocalPlugins());

    return manager;
  }
}
